package hu.bme.orarend.client;

import hu.bme.orarend.shared.ScheduleDTO;

import java.util.List;

import org.gwt.advanced.client.datamodel.EditableGridDataModel;
import org.gwt.advanced.client.ui.widget.GridPanel;
import org.gwt.advanced.client.ui.widget.cell.LabelCell;

public class ScheduleGridPanel extends GridPanel
{
  private String[][] data = new String[1][1];
  EditableGridDataModel editableGridDataModel = new EditableGridDataModel( data );

  public void createClassGrid()
  {
    this.createEditableGrid( new String[] { "Tantárgynév", "Tanár", "Létszám", "Nap", "Kezdési idő", "Befejezési idő", "Terem", "Épület", "Emelet", "Ajtó" },
                             new Class[] { LabelCell.class, LabelCell.class, LabelCell.class, LabelCell.class, LabelCell.class, LabelCell.class, LabelCell.class, LabelCell.class, LabelCell.class, LabelCell.class },
                             editableGridDataModel );
    this.getGrid().enableVerticalScrolling( true );
    this.getGrid().setBodyHeight( "150px" );
    this.setBottomPagerVisible( false );
    this.setTopPagerVisible( false );
    this.setBottomToolbarVisible( false );
    this.setTopToolbarVisible( false );
    this.setHeight( "100px" );
    this.display();
  }
  
  public void refreshData( List<ScheduleDTO> scheduleList )
  {
    this.unlock();
    data = new String[scheduleList.size()][10];
    int i = 0;
    for( ScheduleDTO scheduleDTO:scheduleList )
    {
      data[i][0] = scheduleDTO.getCl().getName();
      data[i][1] = scheduleDTO.getCl().getTeacher();
      data[i][2] = String.valueOf( scheduleDTO.getCl().getNumber() );
      data[i][3] = scheduleDTO.getCl().getDay();
      data[i][4] = scheduleDTO.getCl().getStart();
      data[i][5] = scheduleDTO.getCl().getEnd();
      data[i][6] = scheduleDTO.getRoom().getName();
      data[i][7] = scheduleDTO.getRoom().getBuilding();
      data[i][8] = scheduleDTO.getRoom().getFloor();
      data[i][9] = scheduleDTO.getRoom().getDoor();
      
      i++;
    }
    editableGridDataModel.update( data );
    this.lock();
    this.adjust();
  }
}
